<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员登录 - 银行管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .login-container {
            width: 400px;
            padding: 30px;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }
        .login-title {
            text-align: center;
            color: #0d47a1;
            margin-bottom: 30px;
        }
        .btn-primary {
            background-color: #1976d2;
            border-color: #1976d2;
            width: 100%;
        }
        .btn-primary:hover {
            background-color: #0d47a1;
            border-color: #0d47a1;
        }
        .login-footer {
            text-align: center;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h2 class="login-title">管理员登录</h2>
    <div id="alertContainer"></div>

    <form id="loginForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" name="username" required>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" name="password" required>
        </div>

        <button type="submit" class="btn btn-primary btn-lg">登录</button>
    </form>

    <div class="login-footer">
        <a href="/">返回首页</a>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 通用提示框
    function showAlert(message, type) {
        const alertDiv = $('<div class="alert alert-' + type + ' alert-dismissible fade show" role="alert">' +
            message +
            '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
            '<span aria-hidden="true">&times;</span>' +
            '</button>' +
            '</div>');

        $('#alertContainer').html(alertDiv);

        setTimeout(function() {
            alertDiv.alert('close');
        }, 3000);
    }

    $(document).ready(function() {
        // 表单提交
        $('#loginForm').submit(function(e) {
            e.preventDefault();

            const username = $('#username').val();
            const password = $('#password').val();

            // 验证表单
            if (!username || !password) {
                showAlert('用户名和密码不能为空', 'danger');
                return;
            }

            // 发送登录请求
            $.ajax({
                url: '/admin/do-login',
                type: 'POST',
                data: {
                    username: username,
                    password: password
                },
                success: function(response) {
                    if (response.code === 200) {
                        // 登录成功
                        showAlert('登录成功，正在跳转...', 'success');
                        setTimeout(function() {
                            window.location.href = '/admin/index';
                        }, 1000);
                    } else {
                        // 登录失败
                        showAlert(response.msg || '登录失败', 'danger');
                    }
                },
                error: function() {
                    showAlert('服务器错误，请稍后重试', 'danger');
                }
            });
        });
    });
</script>
</body>
</html> 